package edu.neu.swc.commerce.controller;

import edu.neu.swc.commerce.feign.SentinelFeignClient;
import edu.neu.swc.commerce.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1>Open feign 集成 Sentinel 实现服务降级</h1>
 */
@Slf4j
@RequestMapping("/sentinel-feign")
@RestController
public class SentinelFeignController {

    private final SentinelFeignClient sentinelFeignClient;

    public SentinelFeignController(SentinelFeignClient sentinelFeignClient) {
        this.sentinelFeignClient = sentinelFeignClient;
    }

    @GetMapping("/result-by-feign")
    public CommonResponse<String> getResultByFeign(@RequestParam Integer code){
        log.info("coming in get result by feign:[{}]",
                code);
        return sentinelFeignClient.getResultByFeign(code);
    }
}
